package admin

import (
	"VirtualCamera/common"
	"VirtualCamera/controllers"
	"fmt"
	"strconv"
	"strings"

	//"VirtualCamera/controllers"
	"VirtualCamera/models"
	"VirtualCamera/response"
	//"context"
	//"fmt"
	//"net/http"

	"github.com/gin-gonic/gin"
)
type UserController struct {
	controllers.BaseController
}
// 返回用户的关注列表
func (con UserController) GetUserInterestedGames(c *gin.Context) {
	db := common.GetDB()
	// 定义用户实例
	var user models.User
	// 获取用户的Id
	userId :=c.Query("userId")
	// 测试
	fmt.Println(userId)
	// 根据Id查询用户信息
	db.Where("id = ?",userId).First(&user)
	// 取得用户的interested_games
	interestedGames := user.InterestedGames
	// 将collections转换为数组
	interestedArr := strings.Split(interestedGames,",")
	var interesteds []int
	for _,item := range interestedArr{
		item1,_ := strconv.Atoi(item)
		interesteds = append(interesteds,int(item1))
	}
	var games [] models.Game
	// 根据游戏id列表查询游戏
	db.Find(&games,interesteds)
	ret := gin.H{
		"interested_games": interesteds,
		"games":games,
	}
	response.Success(c,ret,"获取点赞游戏列表成功")
}
// 返回用户的收藏列表
func (con UserController) GetUserCollecyions(c *gin.Context) {
	db := common.GetDB()
	// 定义用户实例
	var user models.User
	// 获取用户的Id
	userId := c.Query("userId")
	// 测试
	fmt.Println(userId)
	// 根据Id查询用户信息
	db.Where("id = ?",userId).First(&user)
	// 获取用户的collections字符串
	collections := user.CollectedGames
	// 将collections转换为数组
	collcetionsArr := strings.Split(collections,",")
	var collectionGames []int
	for _,item := range collcetionsArr{
		item1,_ := strconv.Atoi(item)
		collectionGames = append(collectionGames,int(item1))
	}
	var games [] models.Game
	// 根据游戏id列表查询游戏
	db.Find(&games,collectionGames)
	ret := gin.H{
		"collections":collectionGames,
		"games":games,
	}
	response.Success(c,ret,"获取成功")
}
